<?php
class ModuleController extends Zend_Controller_Action
{
    public function init()
    {
        Zend_Loader::loadClass('My_Graph');
        Zend_Loader::loadClass('My_Link');
        Zend_Loader::loadClass('My_Wertex');
        Zend_Loader::loadClass('My_Object');

        $this->graph  = new My_Graph($this->_getParam('graph', 1));
        $this->view->graph = $this->graph;

        $this->vertexId = $this->_getParam('id', $this->graph->getFirst());

        $wertex = new My_Wertex($this->vertexId);
        $this->object = new My_Object($wertex->getObject());

        foreach($this->object->getPluginClassNames() AS $i => $plugin){
            Zend_Loader::loadClass('Plugin_'.$plugin.'_Class');
            eval('$this->plugins[$i] = new Plugin_'.$plugin.'_Class($this->vertexId);');
        }
/*
        $this->childsWertexId = array();
        $links = new My_Link();
        $links->readByStart($this->vertexId);
        foreach($links->data AS $link){
            $link = new My_Link($link);
            $wertex = new My_Wertex($link->getEnd());
            $object = new My_Object($wertex->getObject());

            foreach($object->getPluginClassNames() AS $i => $plugin){
                Zend_Loader::loadClass('Plugin_'.$plugin.'_Class');
                eval('$plugins[$i] = new Plugin_'.$plugin.'_Class($wertex->getId());');
            }
            
            $content = new My_Content($graphName, $wertexId);
            
        }
        
        */

        //$this->plugins = array_reverse($this->plugins);
        $this->view->name = $this->object->getName();
        $this->view->vertexId = $this->vertexId;
       // $this->view->childsWertexId = $this->childsWertexId;
    }

    public function indexAction()
    {
        foreach($this->plugins AS $plugin){
            $data = array(
                'name' => $plugin->getName(),
                'content' => $plugin->getContent(),
            );
            $content[] = $data;
        }
        $this->view->content = $content;
    }

    public function showAction()
    {
        foreach($this->plugins AS $plugin){
            $data = array(
                'name' => $plugin->getName(),
                'content' => $plugin->getContent(),
            );
            $content[] = $data;
        }
        $this->view->content = $content;
    }

    public function editAction()
    {
        foreach($this->plugins AS $plugin){
            if(!$plugin->action()){
                $content[] = $plugin->body();
                $message[] = $plugin->getMessage();
            }else{
                $this->_forward('index', 'module', null, array());
            }
        }
        $this->view->content = $content;
        $this->view->message = $message;
    }

}


